﻿using System;
using System.Configuration;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.Threading;

namespace DownService
{
    public partial class Service1 : ServiceBase
    {
        public Service1()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            string root = ConfigurationManager.AppSettings["root"];
            if (root == null || root == "")
            {
                root = "d:\\";
            }
            string sPort = ConfigurationManager.AppSettings["port"];
            if (sPort == null || sPort == "")
            {
                sPort = "10898";
            }
            int iport = 10898;
            if (!int.TryParse(sPort, out iport))
            {
                iport = 10898;
            }
            ThreadPool.QueueUserWorkItem(
                (WaitCallback)delegate(object state)
                {
                    TcpDownServer.Server.Run(
                        iport,
                        root);
                }
            );
            
        }

        protected override void OnStop()
        {
        }
    }
}
